package com.javasm.mb_store_api_final.config.adminLogin.login.controller;

import com.javasm.common.R;

import com.javasm.mb_store_api_final.config.adminLogin.login.service.LoginService;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: xmm
 * <p>
 * &#064;@Description:
 * <p>
 * &#064;@Date 2024/7/26 下午4:43
 */

@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    LoginService loginService;

    @GetMapping("/{phone}/code")
    public R sendCode(@PathVariable String phone) {
        loginService.sendCode(phone);
        return R.ok();
    }
    @PostMapping("/logout")
    public R logout(
            HttpServletRequest request,
            HttpServletResponse response,
            Authentication authentication) {

        //清空session
        new SecurityContextLogoutHandler().logout(request, response, authentication);

        return R.ok("退出成功");
    }


    @PostMapping("/nice")
    public R nice() {
        return R.ok();
    }

}
